var db = require('./models');
var sequelize = db.sequelize;
var User = db['user'];
var Project = db['project'];
function create_project(pro) {
    var result = {};
    return sequelize.transaction(function (t) {
         return User.create({
                    email: pro.email,
                    passwd: pro.passwd,
                    role_id: pro.role_id,
                }).then(function(user) {
                    result['user'] = user;
                    return Project.create({
                        name: pro.name,
                        description: pro.description,
                        admin_id: user.id,
                    });
                }).then(function(project) {
                    result['project'] = project;
                    return result;
                });
    });    
}
User.create({email:'cc.c@qq.com',
    passwd: 'fffgg',
    role_id: '123dd'})

// All the functions

module.exports = {
    create_project: create_project,
}
